import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login'
import list from '@/components/list'
import aaa from '@/components/aaa'
import add from '@/components/Add'
Vue.use(Router)

// eslint-disable-next-line no-unused-vars
let router;
// eslint-disable-next-line no-unused-vars
export default router = new Router({
    routes: [
        {
            path: '/',
            name: 'login',
            component: login
        },
        {
            path: '/list',
            name: 'list',
            component: list
        },
        {
            path:'/aaa',
            name:'aaa',
            component:aaa
        },
        {
            path:'/add',
            name:'add',
            component:add
        }
    ]
})

router.beforeEach((to,from,next)=>{
    if(to.path === '/'||to.path === '/login'){
        return next();
    }
    const tokenStr = window.sessionStorage.getItem("token");
    //没有token,跳转到login页面
    if(!tokenStr){
        return next("/");
    }
    next();
})

